import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class AnimatedAlignExample extends StatefulWidget {
  const AnimatedAlignExample({Key? key}) : super(key: key);

  @override
  State<AnimatedAlignExample> createState() => _AnimatedAlignExampleState();
}

class _AnimatedAlignExampleState extends State<AnimatedAlignExample> {
  int statusIndx = 0;

  static const status = [
    Alignment.topLeft,
    Alignment.topCenter,
    Alignment.topRight,
    Alignment.centerRight,
    Alignment.bottomRight,
    Alignment.bottomCenter,
    Alignment.bottomLeft,
    Alignment.centerLeft,
    Alignment.center,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AnimatedAlignExample'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 250.0,
              height: 250.0,
              color: Colors.green,
              child: AnimatedAlign(
                alignment: status[statusIndx],
                duration: Duration(milliseconds: 1000),
                curve: Curves.fastOutSlowIn,
                widthFactor: 2.0,
                heightFactor: 2.0,
                onEnd: () {
                  if (kDebugMode) {
                    print('动画结束时进入');
                  }
                },
                child: Icon(
                  Icons.ac_unit,
                  size: 40,
                ),
              ),
            ),
            ElevatedButton(
                child: Text('改变alignment参数'),
                onPressed: () {
                  setState(() {
                    if (statusIndx == status.length - 1) {
                      statusIndx = 0;
                      return;
                    }
                    statusIndx += 1;
                    if (kDebugMode) {
                      print(statusIndx);
                    }
                  });
                }),
          ],
        ),
      ),
    );
  }
}
